# vim: ai ts=2 sts=2 et sw=2

import os
import unittest
import hotshot, hotshot.stats

import game.map

class TestPathFinding(unittest.TestCase):
  def setUp(self):
    self.map = game.map.Map()
    self.map.loadMapXML(os.path.join("data", "field.xml"))

  def testFindPathTimed(self):
    profile = hotshot.Profile("findpath.profile")
    profile.runcall(self.map.findPath, (0, 0), (27, 18))
    profile.close()
    stats = hotshot.stats.load("findpath.profile")
    stats.strip_dirs()
    stats.sort_stats('time', 'calls')
    stats.print_stats(20)

  def testFindPath(self):
    expectedPath = [(27, 19), (26, 18), (25, 17), (24, 16), (23, 15),
        (22, 14), (21, 13), (20, 12), (19, 11), (18, 10), (17, 9), (16, 8),
        (15, 7), (14, 6), (13, 5), (12, 4), (11, 3), (10, 2), (9, 1),
        (8, 0), (7, 0), (6, 0), (5, 0), (4, 0), (3, 0), (2, 0), (1, 0)]

    path = self.map.findPath((0, 0), (27, 19))
    self.assertEqual(len(expectedPath), len(path))
    for index in range(len(path)):
      self.assertEqual(expectedPath[index], path[index])
   
if __name__ == '__main__':
  unittest.main()

